<template>
  <div v-loading="pageLoading">
    <z-table :list="list" :tableProps="tableProps" :columns="columns">
      <template v-slot:content="v">
        <span v-if="v.key==='repair_status'"><span :class="v.row.statusClass">{{v.row[v.key]}}</span></span>
        <span v-else>{{v.row[v.key]}}</span>
      </template>
    </z-table>
    <z-pagination :pagination="pagination" :total="total" :page.sync="query.page" :limit.sync="query.size"
      @change="getList"></z-pagination>
  </div>
</template>

<script>
import commonMixin from '@/views/_common/mixin'
const statusClass = { Y: 'bg-green', N: 'bg-red' }

export default {
  mixins: [commonMixin],
  props: {
    sn: {
      type: String,
      default: '',
    },
  },
  watch: {
    sn: {
      handler(n, o) {
        if (n) {
          this.query.queryString.sn = n
          this.getList()
        } else {
          this.list = []
          this.total = 0
        }
      },
      immediate: true,
    },
  },
  data() {
    return {
      tableProps: {
        hideOperations: true,
      },
      api: '',
      apiList: this.$api.repairReport,
      query: {
        queryString: {
          sn: null,
        },
        page: 1,
        size: 10,
      },
      columns: [
        { title: '工单号', key: 'mo_no', width: 140, fixed: 'left' },
        { title: '流水号', key: 'serial_number', width: 170, fixed: 'left' },
        { title: '产品型号编码', key: 'sku_no', width: 100 },
        { title: '产品型号名称', key: 'sku_name', width: 120 },
        { title: '产品规格', key: 'sku_spec', width: 180 },
        { title: '测试线别', key: 'test_line_name', width: 100 },
        { title: '测试工序', key: 'test_group_name', width: 100 },
        { title: '不良代码', key: 'test_code', width: 100 },
        { title: '不良描述', key: 'error_description', width: 100 },
        { title: '不良数量', key: 'error_qty', width: 90 },
        { title: '测试时间', key: 'test_time', width: 140 },
        { title: '测试人', key: 'tester', width: 100 },
        { title: '维修线别', key: 'repair_line_name', width: 100 },
        { title: '维修工序', key: 'repair_group_name', width: 100 },
        { title: '维修OK数量', key: 'repair_ok_qty', width: 100 },
        { title: '维修NG数量', key: 'repair_ng_qty', width: 100 },
        { title: '维修时间', key: 'test_time', width: 140 },
        { title: '维修原因', key: 'repair_reason', width: 120 },
        { title: '维修人', key: 'repairer', width: 100 },
        { title: '维修人姓名', key: 'repairer_name', width: 100 },
        { title: '维修结果', key: 'repair_status', width: 70, fixed: 'right' },
      ],
    }
  },
  created() {},
  methods: {
    formatList(data) {
      return data.map((item) => {
        let tmp = { ...item }
        tmp.statusClass = 'text-label ' + statusClass[tmp.repair_status]
        return tmp
      })
    },
  },
}
</script>

<style>
</style> 